home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / game / shoot / ADoom_src_1_1.lha / ADoom_src / r_things.c < prev    next >
C/C++ Source or Header  |  1998-02-19  |  21KB  |  1,022 lines

  1. // Emacs style mode select   -*- C++ -*- 
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. // $Log:$
  18. //
  19. // DESCRIPTION:
  20. //    Refresh of things, i.e. objects represented by sprites.
  21. //
  22. //-----------------------------------------------------------------------------
  23.  
  24.  
  25. static const char
  26. rcsid[] = "$Id: r_things.c,v 1.5 1997/02/03 16:47:56 b1 Exp $";
  27.  
  28.  
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31.  
  32.  
  33. #include "doomdef.h"
  34. #include "m_swap.h"
  35.  
  36. #include "i_system.h"
  37. #include "z_zone.h"
  38. #include "w_wad.h"
  39.  
  40. #include "r_local.h"
  41.  
  42. #include "doomstat.h"
  43.  
  44.  
  45.  
  46. #define MINZ                (FRACUNIT*4)
  47. //#define BASEYCENTER            100
  48. #define BASEYCENTER ((weirdaspect==1)?100:75)
  49.  
  50. //void R_DrawColumn (void);
  51. //void R_DrawFuzzColumn (void);
  52.  
  53.  
  54.  
  55. typedef struct
  56. {
  57.     int        x1;
  58.     int        x2;
  59.     
  60.     int        column;
  61.     int        topclip;
  62.     int        bottomclip;
  63.  
  64. } maskdraw_t;
  65.  
  66.  
  67.  
  68. //
  69. // Sprite rotation 0 is facing the viewer,
  70. //  rotation 1 is one angle turn CLOCKWISE around the axis.
  71. // This is not the same as the angle,
  72. //  which increases counter clockwise (protractor).
  73. // There was a lot of stuff grabbed wrong, so I changed it...
  74. //
  75. fixed_t        pspritescale;
  76. fixed_t        pspriteiscale;
  77. //fixed_t        pspritescale2;
  78. fixed_t        pspriteiscale2;
  79.  
  80. lighttable_t**    spritelights;
  81.  
  82. // constant arrays
  83. //  used for psprite clipping and initializing clipping
  84. //short        negonearray[SCREENWIDTH];
  85. //short        screenheightarray[SCREENWIDTH];
  86. short        *negonearray;
  87. short        *screenheightarray;
  88.  
  89.  
  90. //
  91. // INITIALIZATION FUNCTIONS
  92. //
  93.  
  94. // variables used to look up
  95. //  and range check thing_t sprites patches
  96. spritedef_t*    sprites;
  97. int        numsprites;
  98.  
  99. FAR spriteframe_t    sprtemp[29];
  100. int        maxframe;
  101. char*        spritename;
  102.  
  103.  
  104.  
  105.  
  106. //
  107. // R_InstallSpriteLump
  108. // Local function for R_InitSprites.
  109. //
  110. void
  111. R_InstallSpriteLump
  112. ( int        lump,
  113.   unsigned    frame,
  114.   unsigned    rotation,
  115.   boolean    flipped )
  116. {
  117.     int        r;
  118.     
  119.     if (frame >= 29 || rotation > 8)
  120.     I_Error("R_InstallSpriteLump: "
  121.         "Bad frame characters in lump %i", lump);
  122.     
  123.     if ((int)frame > maxframe)
  124.     maxframe = frame;
  125.         
  126.     if (rotation == 0)
  127.     {
  128.     // the lump should be used for all rotations
  129.     if (sprtemp[frame].rotate == false)
  130.         I_Error ("R_InitSprites: Sprite %s frame %c has "
  131.              "multip rot=0 lump", spritename, 'A'+frame);
  132.  
  133.     if (sprtemp[frame].rotate == true)
  134.         I_Error ("R_InitSprites: Sprite %s frame %c has rotations "
  135.              "and a rot=0 lump", spritename, 'A'+frame);
  136.             
  137.     sprtemp[frame].rotate = false;
  138.     for (r=0 ; r<8 ; r++)
  139.     {
  140.         sprtemp[frame].lump[r] = lump - firstspritelump;
  141.         sprtemp[frame].flip[r] = (byte)flipped;
  142.     }
  143.     return;
  144.     }
  145.     
  146.     // the lump is only used for one rotation
  147.     if (sprtemp[frame].rotate == false)
  148.     I_Error ("R_InitSprites: Sprite %s frame %c has rotations "
  149.          "and a rot=0 lump", spritename, 'A'+frame);
  150.         
  151.     sprtemp[frame].rotate = true;
  152.  
  153.     // make 0 based
  154.     rotation--;        
  155.     if (sprtemp[frame].lump[rotation] != -1)
  156.     I_Error ("R_InitSprites: Sprite %s : %c : %c "
  157.          "has two lumps mapped to it",
  158.          spritename, 'A'+frame, '1'+rotation);
  159.         
  160.     sprtemp[frame].lump[rotation] = lump - firstspritelump;
  161.     sprtemp[frame].flip[rotation] = (byte)flipped;
  162. }
  163.  
  164.  
  165.  
  166.  
  167. //
  168. // R_InitSpriteDefs
  169. // Pass a null terminated list of sprite names
  170. //  (4 chars exactly) to be used.
  171. // Builds the sprite rotation matrixes to account
  172. //  for horizontally flipped sprites.
  173. // Will report an error if the lumps are inconsistant. 
  174. // Only called at startup.
  175. //
  176. // Sprite lump names are 4 characters for the actor,
  177. //  a letter for the frame, and a number for the rotation.
  178. // A sprite that is flippable will have an additional
  179. //  letter/number appended.
  180. // The rotation character can be 0 to signify no rotations.
  181. //
  182. void R_InitSpriteDefs (char** namelist) 
  183.     char**    check;
  184.     int        i;
  185.     int        l;
  186.     int        intname;
  187.     int        frame;
  188.     int        rotation;
  189.     int        start;
  190.     int        end;
  191.     int        patched;
  192.         
  193.     // count the number of sprite names
  194.     check = namelist;
  195.     while (*check != NULL)
  196.     check++;
  197.  
  198.     numsprites = check-namelist;
  199.     
  200.     if (!numsprites)
  201.     return;
  202.         
  203.     sprites = Z_Malloc(numsprites *sizeof(*sprites), PU_STATIC, NULL);
  204.     
  205.     start = firstspritelump-1;
  206.     end = lastspritelump+1;
  207.     
  208.     // scan all the lump names for each of the names,
  209.     //  noting the highest frame letter.
  210.     // Just compare 4 characters as ints
  211.     for (i=0 ; i<numsprites ; i++)
  212.     {
  213.     spritename = namelist[i];
  214.     memset (sprtemp,-1, sizeof(sprtemp));
  215.         
  216.     maxframe = -1;
  217.     intname = *(int *)namelist[i];
  218.     
  219.     // scan the lumps,
  220.     //  filling in the frames for whatever is found
  221.     for (l=start+1 ; l<end ; l++)
  222.     {
  223.         if (*(int *)lumpinfo[l].name == intname)
  224.         {
  225.         frame = lumpinfo[l].name[4] - 'A';
  226.         rotation = lumpinfo[l].name[5] - '0';
  227.  
  228.         if (modifiedgame)
  229.             patched = W_GetNumForName (lumpinfo[l].name);
  230.         else
  231.             patched = l;
  232.  
  233.         R_InstallSpriteLump (patched, frame, rotation, false);
  234.  
  235.         if (lumpinfo[l].name[6])
  236.         {
  237.             frame = lumpinfo[l].name[6] - 'A';
  238.             rotation = lumpinfo[l].name[7] - '0';
  239.             R_InstallSpriteLump (l, frame, rotation, true);
  240.         }
  241.         }
  242.     }
  243.     
  244.     // check the frames that were found for completeness
  245.     if (maxframe == -1)
  246.     {
  247.         sprites[i].numframes = 0;
  248.         continue;
  249.     }
  250.         
  251.     maxframe++;
  252.     
  253.     for (frame = 0 ; frame < maxframe ; frame++)
  254.     {
  255.         switch ((int)sprtemp[frame].rotate)
  256.         {
  257.           case -1:
  258.         // no rotations were found for that frame at all
  259.         I_Error ("R_InitSprites: No patches found "
  260.              "for %s frame %c", namelist[i], frame+'A');
  261.         break;
  262.         
  263.           case 0:
  264.         // only the first rotation is needed
  265.         break;
  266.             
  267.           case 1:
  268.         // must have all 8 frames
  269.         for (rotation=0 ; rotation<8 ; rotation++)
  270.             if (sprtemp[frame].lump[rotation] == -1)
  271.             I_Error ("R_InitSprites: Sprite %s frame %c "
  272.                  "is missing rotations",
  273.                  namelist[i], frame+'A');
  274.         break;
  275.         }
  276.     }
  277.     
  278.     // allocate space for the frames present and copy sprtemp to it
  279.     sprites[i].numframes = maxframe;
  280.     sprites[i].spriteframes = 
  281.         Z_Malloc (maxframe * sizeof(spriteframe_t), PU_STATIC, NULL);
  282.     memcpy (sprites[i].spriteframes, sprtemp, maxframe*sizeof(spriteframe_t));
  283.     }
  284.  
  285. }
  286.  
  287.  
  288.  
  289.  
  290. //
  291. // GAME FUNCTIONS
  292. //
  293. FAR vissprite_t    vissprites[MAXVISSPRITES];
  294. vissprite_t*    vissprite_p;
  295. int        newvissprite;
  296.  
  297.  
  298.  
  299. //
  300. // R_InitSprites
  301. // Called at program start.
  302. //
  303. void R_InitSprites (char** namelist)
  304. {
  305.     int        i;
  306.     
  307.     for (i=0 ; i<SCREENWIDTH ; i++)
  308.     {
  309.     negonearray[i] = -1;
  310.     }
  311.     
  312.     R_InitSpriteDefs (namelist);
  313. }
  314.  
  315.  
  316.  
  317. //
  318. // R_ClearSprites
  319. // Called at frame start.
  320. //
  321. void R_ClearSprites (void)
  322. {
  323.     vissprite_p = vissprites;
  324. }
  325.  
  326.  
  327. //
  328. // R_NewVisSprite
  329. //
  330. vissprite_t    overflowsprite;
  331.  
  332. vissprite_t* R_NewVisSprite (void)
  333. {
  334.     if (vissprite_p == &vissprites[MAXVISSPRITES])
  335.     return &overflowsprite;
  336.     
  337.     vissprite_p++;
  338.     return vissprite_p-1;
  339. }
  340.  
  341.  
  342.  
  343. //
  344. // R_DrawMaskedColumn
  345. // Used for sprites and masked mid textures.
  346. // Masked means: partly transparent, i.e. stored
  347. //  in posts/runs of opaque pixels.
  348. //
  349. short*        mfloorclip;
  350. short*        mceilingclip;
  351.  
  352. fixed_t        spryscale;
  353. fixed_t        sprtopscreen;
  354.  
  355. #ifndef AMIGA
  356. void R_DrawMaskedColumn (column_t* column)
  357. {
  358.     int        topscreen;
  359.     int     bottomscreen;
  360.     fixed_t    basetexturemid;
  361.     
  362.     basetexturemid = dc_texturemid;
  363.     
  364.     for ( ; column->topdelta != 0xff ; ) 
  365.     {
  366.     // calculate unclipped screen coordinates
  367.     //  for post
  368.     topscreen = sprtopscreen + spryscale*column->topdelta;
  369.     bottomscreen = topscreen + spryscale*column->length;
  370.  
  371.     dc_yl = (topscreen+FRACUNIT-1)>>FRACBITS;
  372.     dc_yh = (bottomscreen-1)>>FRACBITS;
  373.         
  374.     if (dc_yh >= mfloorclip[dc_x])
  375.         dc_yh = mfloorclip[dc_x]-1;
  376.     if (dc_yl <= mceilingclip[dc_x])
  377.         dc_yl = mceilingclip[dc_x]+1;
  378.  
  379.     if (dc_yl <= dc_yh)
  380.     {
  381.         dc_source = (byte *)column + 3;
  382.         dc_texturemid = basetexturemid - (column->topdelta<<FRACBITS);
  383.         // dc_source = (byte *)col